package no.hib.mod250.chat.client;

import no.hib.mod250.chat.client.controller.ChatController;
import no.hib.mod250.chat.client.service.ChatService;
import no.hib.mod250.chat.client.service.ChatServiceAsync;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.GWT.UncaughtExceptionHandler;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class PrototypeChat implements EntryPoint {

	ChatServiceAsync chatService = GWT.create(ChatService.class);
	
	RootPanel root = null;
	private RootPanel root_1;
	
	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {

		ChatServiceAsync chatService = GWT.create(ChatService.class);
		root_1 = RootPanel.get("root");

		// Not sure why I have to set this manually
		ServiceDefTarget endpoint = (ServiceDefTarget) chatService;
		endpoint.setServiceEntryPoint(GWT.getModuleBaseURL());

		// Register uncaught exception
		GWT.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {

			@Override
			public void onUncaughtException(Throwable e) {
				GWT.log("Uncaught exception", e);
			}
		});

		// Chat Controller
		ChatController controller = new ChatController(this, root_1, chatService);
		controller.doLoad();
	}

}
